package com.yimils.core.common.oss;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OssConfigure {
    @Value("${ymls.oss.accesskey}")
    private String accessKey;

    @Value("${ymls.oss.accessSecret}")
    private String accessSecret;

    @Value("${ymls.oss.endpoint}")
    private String endpoint;

    @Value("${ymls.oss.bucketName}")
    private String bucketName;

    @Bean
    public OssUtils ossUtils() {
        OssUtils utils =  new OssUtils();
        utils.setAccessKey(accessKey);
        utils.setAccessSecret(accessSecret);
        utils.setBucketName(bucketName);
        utils.setEndpoint(endpoint);
        OSS ossClient = new OSSClientBuilder().build(endpoint,accessKey,accessSecret);
        utils.setOssClient(ossClient);
        return utils;
    }
}
